package Entities;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

@Entity
@NamedQueries({
    @NamedQuery(name = "todasFacturas", query = "select f from Factura f")})
public class Factura implements Serializable {

    private static final long serialVersionUID = 1L;
    //Atributos
    @SequenceGenerator(name = "seq", initialValue = 1, allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
    @Id
    private int id;
    private int rut;
    @OneToOne(fetch = FetchType.EAGER)
    private Pedido pedido;

    //Constructores
    public Factura() {
    }

    public Factura(int rut, Pedido pedido) {
        this.rut = rut;
        this.pedido = pedido;
    }

    //Getters and Setters
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getRut() {
        return rut;
    }

    public void setRut(int rut) {
        this.rut = rut;
    }

    public Pedido getPedido() {
        return pedido;
    }

    public void setPedido(Pedido pedido) {
        this.pedido = pedido;
    }

    //toString
    @Override
    public String toString() {
        return "Entitys.Factura[ id=" + id + " ]";
    }
}
